﻿namespace KeRui.DAL
{
    using KeRui.DBUtility;
    using KeRui.Model;
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class CmsCatchParse
    {
        public int Add(KeRui.Model.CmsCatchParse model)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ParseName", SqlDbType.NVarChar, 50), new SqlParameter("@ListParseBegin", SqlDbType.NVarChar), new SqlParameter("@ListParseEnd", SqlDbType.NVarChar), new SqlParameter("@ListParseTags", SqlDbType.NVarChar), new SqlParameter("@ListParseAttrs", SqlDbType.NVarChar), new SqlParameter("@ListParseRule", SqlDbType.NVarChar), new SqlParameter("@ContentUrl", SqlDbType.NVarChar), new SqlParameter("@ContentParseBegin", SqlDbType.NVarChar), new SqlParameter("@ContentParseEnd", SqlDbType.NVarChar), new SqlParameter("@ContentParseTags", SqlDbType.NVarChar), new SqlParameter("@ContentParseAttrs", SqlDbType.NVarChar), new SqlParameter("@ContentParseRule", SqlDbType.NVarChar), new SqlParameter("@ContentPageParseRule", SqlDbType.NVarChar), new SqlParameter("@ListEncoding", SqlDbType.VarChar, 50), new SqlParameter("@ContentEncoding", SqlDbType.VarChar, 50) };
            parameters[0].Value = model.ParseName;
            parameters[1].Value = model.ListParseBegin;
            parameters[2].Value = model.ListParseEnd;
            parameters[3].Value = model.ListParseTags;
            parameters[4].Value = model.ListParseAttrs;
            parameters[5].Value = model.ListParseRule;
            parameters[6].Value = model.ContentUrl;
            parameters[7].Value = model.ContentParseBegin;
            parameters[8].Value = model.ContentParseEnd;
            parameters[9].Value = model.ContentParseTags;
            parameters[10].Value = model.ContentParseAttrs;
            parameters[11].Value = model.ContentParseRule;
            parameters[12].Value = model.ContentPageParseRule;
            parameters[13].Value = model.ListEncoding;
            parameters[14].Value = model.ContentEncoding;
            return DbHelperSQL.RunProcedure("CmsCatchParse_ADD", parameters, out num);
        }

        public int Delete(int ParseID)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ParseID", SqlDbType.Int, 4) };
            parameters[0].Value = ParseID;
            return DbHelperSQL.RunProcedure("CmsCatchParse_Delete", parameters, out num);
        }

        public bool Exists(int ParseID)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ParseID", SqlDbType.Int, 4) };
            parameters[0].Value = ParseID;
            return (DbHelperSQL.RunProcedure("CmsCatchParse_Exists", parameters, out num) == 1);
        }

        public KeRui.Model.CmsCatchParse GetModel(int ParseID)
        {
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ParseID", SqlDbType.Int, 4) };
            parameters[0].Value = ParseID;
            KeRui.Model.CmsCatchParse parse = new KeRui.Model.CmsCatchParse();
            DataSet set = DbHelperSQL.RunProcedure("CmsCatchParse_GetModel", parameters, "ds");
            if (set.Tables[0].Rows.Count > 0)
            {
                if (set.Tables[0].Rows[0]["ParseID"].ToString() != "")
                {
                    parse.ParseID = int.Parse(set.Tables[0].Rows[0]["ParseID"].ToString());
                }
                parse.ParseName = set.Tables[0].Rows[0]["ParseName"].ToString();
                if (set.Tables[0].Rows[0]["IsUsing"].ToString() != "")
                {
                    parse.IsUsing = int.Parse(set.Tables[0].Rows[0]["IsUsing"].ToString());
                }
                parse.ListParseBegin = set.Tables[0].Rows[0]["ListParseBegin"].ToString();
                parse.ListParseEnd = set.Tables[0].Rows[0]["ListParseEnd"].ToString();
                parse.ListParseTags = set.Tables[0].Rows[0]["ListParseTags"].ToString();
                parse.ListParseAttrs = set.Tables[0].Rows[0]["ListParseAttrs"].ToString();
                parse.ListParseRule = set.Tables[0].Rows[0]["ListParseRule"].ToString();
                parse.ContentUrl = set.Tables[0].Rows[0]["ContentUrl"].ToString();
                parse.ContentParseBegin = set.Tables[0].Rows[0]["ContentParseBegin"].ToString();
                parse.ContentParseEnd = set.Tables[0].Rows[0]["ContentParseEnd"].ToString();
                parse.ContentParseTags = set.Tables[0].Rows[0]["ContentParseTags"].ToString();
                parse.ContentParseAttrs = set.Tables[0].Rows[0]["ContentParseAttrs"].ToString();
                parse.ContentParseRule = set.Tables[0].Rows[0]["ContentParseRule"].ToString();
                parse.ContentPageParseRule = set.Tables[0].Rows[0]["ContentPageParseRule"].ToString();
                if (set.Tables[0].Rows[0]["CreateTime"].ToString() != "")
                {
                    parse.CreateTime = DateTime.Parse(set.Tables[0].Rows[0]["CreateTime"].ToString());
                }
                if (set.Tables[0].Rows[0]["UpdateTime"].ToString() != "")
                {
                    parse.UpdateTime = DateTime.Parse(set.Tables[0].Rows[0]["UpdateTime"].ToString());
                }
                parse.ListEncoding = set.Tables[0].Rows[0]["ListEncoding"].ToString();
                parse.ContentEncoding = set.Tables[0].Rows[0]["ContentEncoding"].ToString();
                return parse;
            }
            return null;
        }

        public int Update(KeRui.Model.CmsCatchParse model)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ParseID", SqlDbType.Int, 4), new SqlParameter("@ParseName", SqlDbType.NVarChar, 50), new SqlParameter("@ListParseBegin", SqlDbType.NVarChar), new SqlParameter("@ListParseEnd", SqlDbType.NVarChar), new SqlParameter("@ListParseTags", SqlDbType.NVarChar), new SqlParameter("@ListParseAttrs", SqlDbType.NVarChar), new SqlParameter("@ListParseRule", SqlDbType.NVarChar), new SqlParameter("@ContentUrl", SqlDbType.NVarChar), new SqlParameter("@ContentParseBegin", SqlDbType.NVarChar), new SqlParameter("@ContentParseEnd", SqlDbType.NVarChar), new SqlParameter("@ContentParseTags", SqlDbType.NVarChar), new SqlParameter("@ContentParseAttrs", SqlDbType.NVarChar), new SqlParameter("@ContentParseRule", SqlDbType.NVarChar), new SqlParameter("@ContentPageParseRule", SqlDbType.NVarChar), new SqlParameter("@ListEncoding", SqlDbType.VarChar, 50), new SqlParameter("@ContentEncoding", SqlDbType.VarChar, 50) };
            parameters[0].Value = model.ParseID;
            parameters[1].Value = model.ParseName;
            parameters[2].Value = model.ListParseBegin;
            parameters[3].Value = model.ListParseEnd;
            parameters[4].Value = model.ListParseTags;
            parameters[5].Value = model.ListParseAttrs;
            parameters[6].Value = model.ListParseRule;
            parameters[7].Value = model.ContentUrl;
            parameters[8].Value = model.ContentParseBegin;
            parameters[9].Value = model.ContentParseEnd;
            parameters[10].Value = model.ContentParseTags;
            parameters[11].Value = model.ContentParseAttrs;
            parameters[12].Value = model.ContentParseRule;
            parameters[13].Value = model.ContentPageParseRule;
            parameters[14].Value = model.ListEncoding;
            parameters[15].Value = model.ContentEncoding;
            return DbHelperSQL.RunProcedure("CmsCatchParse_Update", parameters, out num);
        }
    }
}

